package com.myaihui.controller.admin;

import com.myaihui.domain.SysUser;
import com.myaihui.domain.UserPropertyDossier;
import com.myaihui.foundation.model.Pager;
import com.myaihui.foundation.query.UserPropertyDossierQuery;
import com.myaihui.service.SysUserService;
import com.myaihui.service.UserPropertyDossierService;
import com.myaihui.util.LoginUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * *******************************
 * Created by Tim.
 * form com.matt
 * on 2018/6/11
 * *******************************
 */
@RequestMapping(value = "/user_property_dossier")
@Controller
public class UserPropertyDossierController {

    @Autowired
    private UserPropertyDossierService userPropertyDossierService;

    @Autowired
    private SysUserService sysUserService;

    @RequestMapping(value = "/")
    public ModelAndView home(){
        ModelAndView modelAndView = new ModelAndView("userPropertyDossier/home");
        return modelAndView;
    }

    @RequestMapping("/page")
    @ResponseBody
    public Pager<UserPropertyDossier> page(UserPropertyDossierQuery query){
        SysUser sysUser = sysUserService.findByUsername(LoginUtil.loginUser().getUsername());
        query.setType(sysUser.getType());
        query.setPlatformId(sysUser.getPlatformId());
        if (query.getStatus() ==-1)
            query.setStatus(null);
        return userPropertyDossierService.findByConditions(query);
    }

    @RequestMapping("/{id}")
    public ModelAndView detail(@PathVariable String id){
        ModelAndView modelAndView = new ModelAndView("userPropertyDossier/detail");
        modelAndView.addObject("dossier", userPropertyDossierService.detail(id));
        return modelAndView;
    }

    @RequestMapping("/audit/{id}")
    public ModelAndView audit(@PathVariable String id, Integer status, String remark){
        userPropertyDossierService.audit(id, status, remark);
        return new ModelAndView("redirect:/user_property_dossier/");
    }
}
